#ifndef OSSL_USER_LINUX_H
#define OSSL_USER_LINUX_H

#include <pthread.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <assert.h>
#include <limits.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stddef.h>
#include <errno.h>
#include <syslog.h>
#include <netinet/in.h>
#include "ossl_user.h"
#include "ossl_types.h"

#define uda_printf(x, args...) (void)printf(x, ##args)

#define uda_str2l strtol

#define uda_mkdir(path) mkdir(path, S_IRWXU)

#define PWD_STR "./"
#define DIR_BREAK_CHAR '/'
#define DIR_BREAK_STRING "/"
#ifdef __HIFC__
#define HINICADM_LOG_DIR_PATH "/opt/hifc/"
#define HINICADM_LOCK_DIR_PATH HINICADM_LOG_DIR_PATH
#define HINIC3_DEV_PATH "/dev/hifc_dev"
#define SSSNIC_DEV_PATH "/dev/hifc_dev"
#define CMP_SSSNIC_DEV_NAME "sssnic"
#define CMP_HINIC_DEV_NAME "hifc"
#define HINICADM_FIRMWARE_LOG_DIR_PATH "/opt/hifc/fwlog/"
#else
#define HINICADM_LOG_DIR_PATH "/opt/hinic/"
#define HINICADM_LOCK_DIR_PATH HINICADM_LOG_DIR_PATH
#define HINIC3_DEV_PATH "/dev/hinic3_nictool_dev"
#define SSSNIC_DEV_PATH "/dev/sssnic_nictool_dev"
#define CMP_SSSNIC_DEV_NAME "sssnic"
#define CMP_HINIC_DEV_NAME "hinic"
#define HINICADM_FIRMWARE_LOG_DIR_PATH "/opt/hinic/fwlog/"
#endif

/* The forced speed, in units of 1Mb. All values 0 to INT_MAX are legal. */


#define UDA_SIGINT SIGINT
#define UDA_SIGTERM SIGTERM
#define UDA_SIGHUP SIGHUP
#define UDA_SIGTSTP SIGTSTP

#define U32_MASK ((u32)(~((u32)0))) /* 0xFFFFFFFF         */
#define NIC_TOOL_MAGIC 'x'

#ifndef TRUE
#define TRUE (1)
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#define LINUX_DEFAULT_ID (0x0)
#define NICTOOL_CMD_TYPE (0x18)
#define DEVICE_ONE_STRING (1)
#define DEVICE_NAME_OFFSET (3)
#ifndef IFNAMSIZ
#define IFNAMSIZ 16
#endif
#define MAX_NUM_OF_PATH_ULOG 128

#ifndef TOOL_COMPILE_TAG
#define TOOL_COMPILE_TAG "git xxxxxxxx"
#endif

#define UDA_MAJOR_CMD_ERR 2
#define UDA_HALF_CMD_ERR 3
#define UDA_HELP_PRINT 4
#define UDA_FORMATE_ERR 5
#define UDA_DEV_ERR 6
#define UDA_GET_COMPILE_TIME 7
#define LOG_PRIORITY_INFO LOG_INFO
#define TOOL_PID_MAX_LEN 10
#define MGMT_TOOL_COMPILE_TAG TOOL_COMPILE_TAG

void select_dev_path(char *name);
bool string_cmp(const char *cmd, const char *argc);

s32 open_lockf_file(const char *lock_file, u32 len, long *fd);
s32 uda_lockf(u32 operation, const long fd);
s32 uda_unlockf(const long fd);
s32 get_lockf_status(const long fd);

extern s32 uda_get_bus_num(char *name, size_t len, int *bus_num);
extern s32 uda_realpath(const char *file_dir, size_t len, char *format_dir, size_t size);
extern uda_status uda_flock(const char *lock_file, u32 len, u32 operation, long *fd);
extern uda_status uda_unflock(const long *fd);
extern int create_file(void);
extern void close_file(int fd);
extern uda_status uda_access(const char *file_dir);
extern int uda_create_file_name(const u8 *src_name, u8 file_len, const u8 *area, const u8 *dev_name, u8 *dest_name);
extern uda_status uda_uncompress_gz_file(const u8 *dev_name);
extern void record_syslog(const char *ident, int priority, char *logs, u32 len);
extern void uda_msleep(long milliseconds);
#endif
